package com.stu.day13.listsort;

import java.util.Comparator;

/**
 * @author zy
 * @date 2025/2/11 19:08
 */
public class OrderSortFactory {
    public static final int ID = 1;
    public static final int ORD_NO = 2;
    public static final int TOTAL = 3;

    public static Comparator<Order2> getInstance(int type){
        Comparator<Order2> c = null;
        switch (type){
            case ID:
                c = new Comparator<Order2>() {
                    @Override
                    public int compare(Order2 o1, Order2 o2) {
                        return o1.getId()-o2.getId();//降序
                    }
                };
                break;
            case ORD_NO:
                c = (o1,o2)->(o2.getOrdNO().compareTo(o1.getOrdNO()));
                break;
            case TOTAL:
                c = (o1,o2)->(int)(o2.getTotal()-o1.getTotal());
                break;
        }
        return c;
    }
}
